/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.AccessManager.AttrRightChecker;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.AttributeClass;
/*    */ import com.zimbra.cs.account.Domain;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.account.XMPPComponent;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetXMPPComponent
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 47 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 48 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 50 */     Set<String> reqAttrs = getReqAttrs(request, AttributeClass.xmppComponent);
/* 51 */     Element id = request.getElement("xmppcomponent");
/* 52 */     String byStr = id.getAttribute("by");
/* 53 */     String name = id.getText();
/*    */     
/* 55 */     if ((name == null) || (name.equals(""))) {
/* 56 */       throw ServiceException.INVALID_REQUEST("must specify a value for a xmppcomponent", null);
/*    */     }
/* 58 */     Key.XMPPComponentBy by = Key.XMPPComponentBy.valueOf(byStr);
/*    */     
/* 60 */     XMPPComponent comp = prov.get(by, name);
/* 61 */     if (comp == null) {
/* 62 */       throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(name);
/*    */     }
/* 64 */     AdminAccessControl aac = checkRight(zsc, context, comp, AdminRight.PR_ALWAYS_ALLOW);
/*    */     
/* 66 */     Element response = zsc.createElement(AdminConstants.GET_XMPPCOMPONENT_RESPONSE);
/* 67 */     encodeXMPPComponent(response, comp, reqAttrs, aac.getAttrRightChecker(comp));
/* 68 */     return response;
/*    */   }
/*    */   
/*    */   public static Element encodeXMPPComponent(Element parent, XMPPComponent comp) {
/* 72 */     return encodeXMPPComponent(parent, comp, null, null);
/*    */   }
/*    */   
/*    */   public static Element encodeXMPPComponent(Element parent, XMPPComponent comp, Set<String> reqAttrs, AccessManager.AttrRightChecker attrRightChecker)
/*    */   {
/* 77 */     Element e = parent.addElement("xmppcomponent");
/* 78 */     e.addAttribute("name", comp.getName());
/* 79 */     e.addAttribute("id", comp.getId());
/*    */     try
/*    */     {
/* 82 */       e.addAttribute("x-domainName", comp.getDomain().getName());
/*    */     }
/*    */     catch (ServiceException ex) {}
/*    */     try {
/* 86 */       e.addAttribute("x-serverName", comp.getServer().getName());
/*    */     }
/*    */     catch (ServiceException ex) {}
/* 89 */     ToXML.encodeAttrs(e, comp.getUnicodeAttrs(), reqAttrs, attrRightChecker);
/* 90 */     return e;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 95 */     relatedRights.add(Rights.Admin.R_getXMPPComponent);
/* 96 */     notes.add(String.format("Attributes that are not allowed to be get by the authenticated admin will be returned as <a n=\"{attr-name}\" pd=\"1\"/>.To allow an admin to get all attributes, grant the %s right", new Object[] { Rights.Admin.R_getXMPPComponent.getName() }));
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetXMPPComponent.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */